package com.framework.middleware.kafka;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.io.*;
import java.util.Properties;

/**
 * @author chaolong.jin
 * @description
 * @date 2019/08/08 19:04
 */
public class Provider {

    public static void main(String[] args) {

        Provider provider = new Provider();
        InputStream inputStream = provider.getClass().getClassLoader().getResourceAsStream("kafka_producer.properties");
        provider.getClass().getClassLoader().getResource("kafka_producer.properties");
        Properties props = new Properties();

        Producer<String, String> producer = null;
        try {
            props.load(inputStream);
            producer = new KafkaProducer<>(props);
            for (int i = 0; i < 2; i++) {
                System.out.println(i);
                producer.send(new ProducerRecord<String, String>("test", Integer.toString(i), Integer.toString(i)));
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            producer.close();
        }


    }

}
